﻿<UserControl 
    x:Class="Sidvall.UI.Wpf.Controls.TreeControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:vms="clr-namespace:Sidvall.UI.ViewModels;assembly=Sidvall.UI"
    xmlns:ig="http://schemas.infragistics.com/xaml" 
    xmlns:Controls="clr-namespace:Sidvall.UI.Wpf.Controls" 
    xmlns:Controls2="clr-namespace:Sidvall.UI.Wpf.Controls;assembly=Sidvall.UI.Wpf" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf"
    mc:Ignorable="d" 
    d:DesignHeight="150" d:DesignWidth="500">

    <UserControl.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Style TargetType="{x:Type ig:XamDataTreeNodeControl}" x:Key="NodeStyle">
            <Setter Property="Visibility" Value="{Binding Node.Data.IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
        </Style>
    </UserControl.Resources>

    <Grid x:Name="ParentGrid" d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:TreeControlViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <ig:XamDataTree x:Name="TreeView" ItemsSource="{Binding TreeItems}" DisplayMemberPath="Name" CheckBoxMemberPath="IsSelected" 
                        IsEnabledMemberPath="IsEnabled" IsExpandedMemberPath="IsExpanded" Visibility="Collapsed"
                        ActiveDataItem="{Binding ActiveTreeItem, Mode=TwoWay}" ActiveNodeChanged="TreeView_ActiveNodeChanged" 
                        Background="{Binding TreeViewBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}"
                        VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" NodeExpansionChanged="TreeView_NodeExpansionChanged">
            <ig:XamDataTree.CheckBoxSettings>
                <ig:CheckBoxSettings CheckBoxVisibility="Collapsed" CheckBoxMode="Manual" IsCheckBoxThreeState="False" />
            </ig:XamDataTree.CheckBoxSettings>
            <ig:XamDataTree.GlobalNodeLayouts>
                <ig:NodeLayout Key="ChildItems" DisplayMemberPath="Name" TargetTypeName="TreeItem" NodeStyle="{StaticResource NodeStyle}" />
            </ig:XamDataTree.GlobalNodeLayouts>
        </ig:XamDataTree>

        <TextBox x:Name="ValueTextBox" Grid.Column="0" Text="{Binding SelectedItemsText, Mode=OneWay}" 
                 Background="{Binding ValueTextBoxBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}" 
                 PreviewKeyDown="ValueTextBox_PreviewKeyDown" />
        <Button Grid.Column="1" Padding="0" Click="ClearSelection_Click" Focusable="False" IsTabStop="False"
                Visibility="{Binding ShowClearButton, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}">
            <Image Source="/Sidvall.UI.Wpf.IG;component/Images/Delete24.png" Margin="6" />
        </Button>
        <ToggleButton x:Name="PopupButton" Grid.Column="2" Padding="0" Cursor="Hand" Focusable="False" 
                      Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked" IsTabStop="False"
                      Width="{Binding PopupButtonWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}">
            <Image Source="/Sidvall.UI.Wpf.IG;component/Images/DownArrow24.png" Margin="{Binding PopupButtonImageMargin, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}" />
        </ToggleButton>

        <Popup x:Name="TreePopup" Grid.Row="1" Grid.ColumnSpan="3" IsOpen="False" StaysOpen="False" Closed="TreePopup_Closed">
        </Popup>
        <Popup x:Name="TreePopupDialog" Grid.Row="1" Grid.ColumnSpan="3" IsOpen="False" Closed="TreePopupDialog_Closed">
            <ig:XamDialogWindow x:Name="TreePopupDialogWindow" IsMoveable="False" MaximizeButtonVisibility="Collapsed" MinimizeButtonVisibility="Collapsed" 
                                CloseButtonVisibility="Collapsed" HeaderIconVisibility="Collapsed" IsModal="True"
                                Width="{Binding Width, ElementName=TreePopupDialog}"
                                Height="{Binding Height, ElementName=TreePopupDialog}"
                                Header="{Binding PopupDialogHeader, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeControl}}}"
                                FocusManager.IsFocusScope="True"
                                Controls2:AccessKeyScoper.IsAccessKeyScope="True">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <ContentControl x:Name="TreePopupDialogContent">

                    </ContentControl>
                    <StackPanel Grid.Row="1" Background="#FFF0F0F0">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Name="ButtonPanel" Margin="0,8,8,8">
                            <Button MinWidth="70" Padding="15,3,15,3" IsCancel="True" Content="Cancel" Margin="8,0,0,0" Click="CancelButton_Click" />
                            <Button MinWidth="70" Padding="15,3,15,3" IsDefault="True" Content="OK" Margin="8,0,0,0" Click="OKButton_Click" />
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </ig:XamDialogWindow>
        </Popup>
    </Grid>
</UserControl>
